package com.zhiyou100.entity;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.beans.factory.config.ConfigurableBeanFactory;
import org.springframework.context.annotation.Lazy;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.annotation.PreDestroy;
import java.io.Serializable;

/**
 * 学生实体类
 *
 * @author yang
 * @className Student
 * @packageName com.zhiyou100.entity
 * @Description TODO 学生类
 * @date 2020-08-19 09:23
 * <p>
 * <p>
 * // @Component 不确定是那一层
 * // @Service 业务层
 * // @Controller 控制层
 * // @Repository 持久成
 * // @Lazy 懒加载
 * // @Scope 指定空间
 * // @Value("1001") 作用与属性或者 set 方法，设置值
 * // @Resource(name = "tea") 手动装配
 * // @Autowired 自动装配
 * // @PostConstruct 初始化方法
 * // @PreDestroy 销毁方法
 */


@Scope(ConfigurableBeanFactory.SCOPE_SINGLETON)
@Lazy
@Component("stu1")
public class Student implements Serializable {
    @Value("1001")
    private Integer sid;
    private String sname;
    private boolean sdangYan;
    /*
     * 手动装配，指定 id
     */
    //@Resource(name = "tea")
    /**
     * 自动转配
     */
    @Autowired
    private Teacher teacher;

    public Student() {
        System.out.println("Student 执行了！！！");
    }

    public Student(String sname, boolean sdangYan, Teacher teacher) {
        this.sname = sname;
        this.sdangYan = sdangYan;
        this.teacher = teacher;
    }

    @Override
    public String toString() {
        return "Student{" +
                "sid=" + sid +
                ", sname='" + sname + '\'' +
                ", sdangYan=" + sdangYan +
                ", teacher=" + teacher +
                '}';
    }

    public Integer getSid() {
        return sid;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public String getSname() {
        return sname;
    }

    @Value("李雷")
    public void setSname(String sname) {
        this.sname = sname;
    }

    public boolean isSdangYan() {
        return sdangYan;
    }

    public void setSdangYan(boolean sdangYan) {
        this.sdangYan = sdangYan;
    }

    public Teacher getTeacher() {
        return teacher;
    }

    public void setTeacher(Teacher teacher) {
        this.teacher = teacher;
    }

    /**
     * 初始化方法
     */
    @PostConstruct
    public void init() {
        System.out.println("init 方法");
    }

    /**
     * 销毁方法，没有作用
     */
    @PreDestroy
    public void destroy() {
        System.out.println("destroy 方法");
    }
}
